#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

typedef struct LNode
{
   int data;
   struct LNode* next;
} LNode, * LinkList;



LinkList CreateList(int n)
{
   LinkList head = nullptr, p = nullptr;
   head = new LNode;
   head->data = 1;
   head->next = nullptr;
   p = head;
   int i = 2;
   while (i <= n)
   {
       LinkList q = new LNode;
       q->data = i;
       q->next = nullptr;
       p->next = q;
       p = q;
       i++;
   }
   p->next = head;
   return head;
}


LinkList Execute(LinkList h, int k)
{
   LinkList q = new LNode;
   LinkList p = new LNode;

   p = h;

   for (int i = 1; i < k; i++)
   {
       q = p; //q存p的值
       p = p->next; 
   }
       //遍历之后，该出圈的为p.q为p的前一个节点
    q->next = p->next; //删除出区节点
    p = p->next;

   return p;
}


int main()
{
   int n;
   while (cin >> n)
   {
       LinkList h;
       h = CreateList(n);
       while (--n)
           h = Execute(h, 2);
       cout << h->data << endl;
       delete h;
   }
   return 0;
}